import React, { Component, Fragment } from 'react';
// table 组件
import TableComponent from "@c/tableData/Index";

class OperationList extends Component {
  constructor(props) {
    super(props);
    this.state = {
      tableConfig: {
        url: "operationList",
        method: "get",
        checkbox: true,
        thead: [
          { title: "操作人", dataIndex: "ops_user", key: "ops_user" },
          { title: "项目", dataIndex: "ops_project", key: "ops_project" },
          { title: "时间", dataIndex: "add_time", key: "add_time" },
          { title: "请求参数", dataIndex: "request_data", key: "request_data" },
          {
            title: "method/endpoint",
            render: (text, rowData) => {
              return (
                <div>
                  {rowData.ops_method} {rowData.endpoint}
                </div>
              )
            }
          },
          { title: "返回状态码", dataIndex: "status_code", key: "status_code" },
        ],
        formItem: [
          {
            type: "Input",
            label: "URL",
            name: "endpoint",
            placeholder: "请输入"
          },
          { 
            type: "SelectComponent",
            label: "操作人", 
            url: "userList",
            method: "get",
            name: "ops_user",
            propsKey: {
                label: "realname",
                value: "username"
            },
            style: { width: "100px" },
          },
          { 
            type: "SelectComponent",
            label: "事业部", 
            url: "departmentListAll",
            method: "get",
            name: "ops_project",
            propsKey: {
                label: "name",
                value: "code"
            },
            style: { width: "150px" },
        },
        ]
      },
      // 表的数据
      data: []
    };
  }

  // componentDidMount() {}
  // 获取子组件实例
  getChildRef = (ref) => {
    this.tableComponent = ref; // 存储子组件
  }

  render() {
    return (
      <Fragment>
        <TableComponent onRef={this.getChildRef} batchButton={true} config={this.state.tableConfig} />
      </Fragment>
    )
  }
}

export default OperationList;